package com.koi.generator.pojo;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ･ᴗ･
 * @description [TemplatePathParam模版相关参数类]
 */
@Data
public class TemplatePathParam {

    /**
     * 当前日期
     */
    private String currentDate = new SimpleDateFormat("yyyy/MM/dd").format(new Date());

    /**
     * 包名 com.koi.xxx
     */
    private String packageName;

    /**
     * 项目名称 英文 比如：Koi-Admin
     */
    private String projectName;

    /**
     * 实体类生成的绝对路径
     */
    private String entityPath;

    /**
     * Vo实体类生成的绝对路径
     */
    private String entityVoPath;

    /**
     * Dto实体类生成的绝对路径
     */
    private String entityDtoPath;

    /**
     * Bo实体类生成的绝对路径
     */
    private String entityBoPath;

    /**
     * mapper生成绝对路径
     */
    private String mapperPath;

    /**
     * mapper映射文件生成的绝对路径
     */
    private String mapperXmlPath;

    /**
     * service接口生成的绝对路径
     */
    private String servicePath;

    /**
     * service实现类生成的绝对路径
     */
    private String serviceImplPath;

    /**
     * controller生成的绝对路径
     */
    private String controllerPath;

    /**
     * pom文件生成的绝对路径
     */
    private String pomPath;

    /**
     * application.yml文件生成的绝对路径
     */
    private String applicationYmlPath;

    /**
     * api/index.ts文件生成的绝对路径
     */
    private String apiPath;

    /**
     * vue文件生成绝对路径
     */
    private String vuePath;

    /**
     * @description [生成包路径方法]
     * @author ･ᴗ･
     * @param packageName com.koi.generator
     * @param projectName D:\\Koi-Admin-GenCode
     */
    public TemplatePathParam(String projectName, String packageName) {
        if (StringUtils.isBlank(projectName) || StringUtils.isBlank(packageName)) {
            throw new RuntimeException("参数不能为空");
        }
        this.projectName = projectName;
        this.packageName = packageName;

        String[] split = packageName.split("\\.");
        String javaModelPath = projectName + "/src/main/java/" + split[0] + "/" + split[1] + "/" + split[2];
        String xmlModelPath = projectName + "/src/main/resources/mapper/" + split[2];
        this.setEntityPath(javaModelPath + "/pojo");
        this.setMapperPath(javaModelPath + "/mapper");
        this.setMapperXmlPath(xmlModelPath);
        this.setServicePath(javaModelPath + "/service");
        this.setServiceImplPath(javaModelPath + "/service/impl");
        this.setControllerPath(javaModelPath + "/controller");
        this.setEntityVoPath(javaModelPath + "/model/vo");
        this.setEntityBoPath(javaModelPath + "/model/bo");
        this.setEntityDtoPath(javaModelPath + "/model/dto");
        this.setPomPath(projectName);
        this.setApplicationYmlPath("src/main/resources");
        this.setApiPath(projectName + "/api");
        this.setVuePath(projectName + "/vue");
    }

}


